﻿using System;
using System.Collections.Generic;
using System.Text;

namespace IllustratedCsharp7_ch8_virtualandoverride
{
    class chapt8_6_VirtuaAndOverride
    {

        static void _Main()
        {
            MyDerivedClass derived = new MyDerivedClass();
            MyBaseClass mybc = derived;
            derived.Print();
            mybc.Print();
        }
    }
    class MyBaseClass                    //基类
    {

        virtual public void Print()     //虚方法
        {
            Console.WriteLine("This is the base class.");
        }
    }

    class MyDerivedClass : MyBaseClass //派生类
    {
        public int var1;

        override  public void Print()   //覆盖方法
        {
            Console.WriteLine("This is the derived class");
        }
    }
}
